<template>
  <div class="all">
    <div class="add-nav">
      注册时间:
    <el-date-picker
      v-model="time1"
      type="daterange"
      range-separator="至"
      start-placeholder="开始日期"
      end-placeholder="结束日期"
      value-format="yyyy-MM-dd">
    </el-date-picker>
   <el-input type="text" value="" placeholder="请输入用户ID或者用户名" v-model="condition.idOrName"></el-input>
   <el-button type="primary" icon="el-icon-search" @click="search()">搜索</el-button>
    </div>
<div>
  <el-table :data="list" :header-cell-style="{background:'#eef3f7'}">
    <el-table-column label="头像" align="center">
      <template slot-scope="scope">
         <el-avatar shape="square" :size="100" fit="fill" :src="scope.row.imgUrl"></el-avatar>
      </template>
    </el-table-column>
    <el-table-column align="center" prop="userName" label="用户名"></el-table-column>
    <el-table-column align="center" prop="nickName" label="昵称"></el-table-column>
    <el-table-column align="center" prop="city" label="所在地"></el-table-column>
    <el-table-column align="center" prop="age" label="年龄"></el-table-column>
    <el-table-column align="center" prop="sex" label="性别"></el-table-column>
    <el-table-column align="center" prop="earnBean" label="金币"></el-table-column>
    <el-table-column align="center" prop="regTime" label="注册时间"></el-table-column>
    <el-table-column align="center" label="状态">
      <template slot-scope="scope">
        <i v-if="scope.row.sign==0">未签约</i>
         <i v-else>已签约</i>
      </template>
    </el-table-column>
    <el-table-column align="center" label="管理操作">
      <template slot-scope="scope">
        <el-button type="success" size="mini" @click="renew(scope.row)">恢复</el-button>
      </template>
    </el-table-column>
  </el-table>
</div>
    <div class="Page">
          <el-pagination
          background
           hide-on-single-page
            @size-change="handleSizeChange"
            @current-change="handleCurrentChange"
            :current-page="condition.pageIndex"
            :page-sizes="[10, 15, 20, 25]"
            :page-size="100"
            layout="total, sizes, prev, pager, next, jumper"
            :total="condition.quantity">
          </el-pagination>

    </div>
  </div>
</template>


<script>
  export default{
     inject:["reload"],
    data(){
      return{
        select:'list',
        time1: [],
        condition:{
          quantity:10,
          pageIndex:1,
          pageSize:10,
          cancelled:1
        },
        list:[]
        }
        },
    methods:{
      search(){
        this.condition.fromRegTime=this.time1[0]
       this.condition.toRegTime=this.time1[1]
       this.Postdata('admin/user/get',this.condition)
      },
      handleSizeChange(val) {
        this.condition.pageSize=val
        this.Postdata('admin/user/get',this.condition)
      },
       handleCurrentChange(val) {
         this.condition.pageIndex=val
        this.Postdata('admin/user/get',this.condition)

      },
      Postdata(url,e){
              var _this=this
              this.$axios({
                method: "POST",
                url: '/api/'+url,
                headers: {'Content-Type': 'application/json'},
                data: {
                   adminName:_this.$cookies.get('adminName'),
                   token:_this.$cookies.get('token'),
                   fromRegTime:e.fromRegTime,
                   toRegTime:e.toRegTime,
                   idOrName:e.idOrName,
                   sign:e.sign,
                   liveStatus:e.liveStatus,
                   cancelled:e.cancelled,
                   pageIndex:e.pageIndex,
                   pageSize:e.pageSize,
                   userId:e.userId
                  },
                }).then(function(response){
                  if(response.data.code==0){
                    if(response.data.data==null){
                      _this.$alert("操作成功", '提示', {
                             confirmButtonText: '确定',
                             callback: action => {
                               //刷新
                               _this.reload()
                             }
                           });
                    }else{
                      _this.condition.quantity=response.data.data.sum
                      _this.list=response.data.data.members
                    }

                  }else{
                    if(response.data.code==3001){
                      _this.$alert('查无此人', '提示', {
                         confirmButtonText: '确定',
                         callback: action => {
                           _this.reload()
                         }
                       });
                    }else{
                      _this.$alert('查询失败', '提示', {
                         confirmButtonText: '确定',
                         callback: action => {
                         }
                       });
                    }
                  }
                 })
                 .catch(function(error){
                   console.log(error)
                 })
      },
        renew(val){
          var _this=this
             this.$confirm('此操作将恢复'+val.userName+', 是否继续?', '提示', {
            confirmButtonText: '确定',
            cancelButtonText: '取消',
            type: 'warning'
          }).then(() => {
            _this.Postdata('admin/user/recover',val)
            this.$message({
              type: 'success',
              message: '禁用成功!'
            });
          }).catch(() => {
            this.$message({
              type: 'info',
              message: '已取消删除'
            });
          });
        },
},
mounted(){
this.Postdata('admin/user/get',this.condition)

}
        }
</script>

<style lang="scss" scoped>
  .el-input{width: auto;}
</style>
